﻿using System;
using System.Numerics;
using Veldrid;
using Veldrid.Sdl2;
using Veldrid.StartupUtilities;

namespace ImEngine
{
    class Program
    {
        private static Sdl2Window _window;
        private static GraphicsDevice _gd;
        private static CommandList _cl;
        static Vector3 _clearColor = new Vector3(0.45f, 0.55f, 0.65f);

        static void Main(string[] args)
        {
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "ImEngine"),
                new GraphicsDeviceOptions(true, null, true),
                GraphicsBackend.Vulkan,
                out _window,
                out _gd);

            _cl = _gd.ResourceFactory.CreateCommandList();

            while (_window.Exists)
            {
                var snapshop = _window.PumpEvents();
                if (!_window.Exists)
                {
                    break;
                }

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
                _cl.End();

                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }

            _gd.WaitForIdle();
            _cl.Dispose();
            _gd.Dispose();
        }
    }
}
